import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import "."

Window {
    visible: true
    width: 960
    height: 800
    title: qsTr("Hello Table")

    Item {
        anchors.fill: parent

        Row {
            spacing: 5
            CusLabel {
                text: "selectCount:" + deviceAddModel.selectedCount
            }
            CusLabel {
                text: "checkedCount:" + deviceAddModel.checkedCount
            }
            CusLabel {
                text: "visibleCount: " + deviceAddModel.visibledCount
            }

        }
        CusTextField_Search {
            anchors {
                right: parent.right
                rightMargin: 10
                top: parent.top
            }
            onTextChanged: {
                deviceAddModel.search(text)
            }
        }
        CusTableHeader {
            id: cusHeader
            x: 100
            y: 50
            width: 500
            height: 30
            averageCount: 2
            dataObj: deviceAddModel
            headerNames: deviceAddModel.headerRoles
            headerRoles: deviceAddModel.headerRoles
            widthList: cusView.widthList
            xList: cusView.xList
        }
        CusTableView {
            id: cusView
            x: 100
            y: cusHeader.y + cusHeader.height
            width: 780
            height: 640
            model: deviceAddModel
            onPressed: {
                doPress(mouseX, mouseY)
            }
            onReleased: {
                doRelease()
            }
            onPositionChanged: {
                doPositionChanged(mouseX, mouseY)
            }
            delegate: CusTableRow {
                width: cusView.width
                roles: cusView.model.headerRoles
                dataObj: model.display
                widthList: cusHeader.widthList
                xList: cusHeader.xList
                onCheckedChanged: {
                    deviceAddModel.check(index, checked)
                }
            }
        }
        Column {
            x: cusHeader.x + cusHeader.mouseX
            y: cusView.y
            visible: cusHeader.isSpliting && !cusHeader.isOut
            height: cusView.height
            width: 1
            spacing: 2
            Repeater {
                model: (cusHeader.isSpliting
                        && !cusHeader.isOut) ? parent.height / 6 : 0
                Rectangle {
                    width: 1
                    height: 4
                    color: Config.tableStechColor
                }
            }
        }
    }
}
